// api/patient.js
import { 
  mockGetUserList, 
  mockBindingUser, 
  mockUnbindingUser, 
  mockGetPatientDetail,
	mockGetPatientDiagnosis
} from '@/mock/doctor/mockServer.js'

// 是否使用mock数据
const USE_MOCK = true;

// 基础URL
const BASE_URL = 'http://your-api-base-url'; // 替换为你的实际API基础URL

// 获取绑定的用户列表
export const getUserList = (userId) => {
  if (USE_MOCK) {
    return mockGetUserList(userId);
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/doctor/userList`,
      method: 'GET',
      data: { userId },
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

// 绑定病人
export const bindingUser = (userId, bindedUserId) => {
  if (USE_MOCK) {
    return mockBindingUser(userId, bindedUserId);
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/doctor/binding`,
      method: 'POST',
      data: { userId, bindedUserId },
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

// 解绑病人
export const unbindingUser = (userId, bindedUserId) => {
  if (USE_MOCK) {
    return mockUnbindingUser(userId, bindedUserId);
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/doctor/unbinding`,
      method: 'POST',
      data: { userId, bindedUserId },
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

// 获取患者详情
export const getPatientDetail = (id) => {
  if (USE_MOCK) {
    return mockGetPatientDetail(id);
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/doctor/patientDetail/${id}`,
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

// 获取患者病情
export const getPatientDiagnosis = (id) => {
	if(USE_MOCK) {
		return mockGetPatientDiagnosis(id);
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${BASE_URL}/api/doctor/patientDiagnosis/${id}`,
			method: 'GET',
			success: (res) => {
				resolve(res.data);
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
}
